package com.tyrone.concurrent.basic;

import com.tyrone.concurrent.utils.SleepUtils;

import java.util.concurrent.TimeUnit;

/**
 * 线程的状态
 * jps(查看线程Id) jstack 查看相对应线程的详细信息
 * @author xieyl
 * @create 2021/11/30 21:21
 */
public class ThreadState {
    public static void main(String[] args) {
        new Thread(new TimeWaiting(),"TimeWaitingThread").start();
        new Thread(new Waiting(),"WaitingThread").start();
        //使用两个Blocked 线程
        Thread thread = new Thread(new Blocked(), "BlockThread-1");
        thread.setPriority(10);
        thread.start();
        new Thread(new Blocked(),"BlockThread-2").start();

    }
    static class TimeWaiting implements Runnable {
        @Override
        public void run() {
             SleepUtils.second(10);
        }
    }
    static class Waiting implements Runnable{
        @Override
        public void run() {
            while (true){
                synchronized (Waiting.class){
                    try{
                        Waiting.class.wait();
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    static class Blocked implements Runnable{
        @Override
        public void run() {
            synchronized (Blocked.class){
                while (true){
                    SleepUtils.second(100);
                }
            }
        }
    }

}
